<template>

  <a-card :bordered="false">

    <!-- <transition name="fade" v-if="showImg">-->
    <div class="img-view" v-if="showImg">
      <!-- 遮罩层 -->
      <div class="img-layer" v-if="showImg" @click="viewImg"></div>

      <div  v-show="jianShow">
        <img :src="leftjian" class="left" @click="handleClickLeft"/>
      </div>

      <div class="img" v-if="showImg" @click="viewImg" >
        <img :src="imgSrc[imgIndex]">
      </div>

      <div v-show="jianShow">
        <img :src="jiantou" class="right" @click="handleClickRight"/>
      </div>

    </div>
    <!--</transition>-->

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="打卡人姓名">
              <a-input placeholder="请输入打卡人姓名" v-model="queryParam.createName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="12" :sm="24">
            <a-form-item label="打卡日期">
              <a-date-picker
                placeholder="请选择打卡日期"
                format='YYYY-MM-DD'
                valueFormat="YYYY-MM-DD"
                v-decorator="[ 'startTime', {}]"
                style="width:100%" v-model="queryParam.createDate"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="审批人">
              <a-input placeholder="请输入审批人" v-model="queryParam.updateName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item
              label="审批状态">
              <a-select default-value=""
                        v-decorator="[ 'bpmStatus', {}]"
                        placeholder="请选择状态" v-model="queryParam.bpmStatus"
                        :getPopupContainer = "(target) => target.parentNode">
                <!--                <a-select-option value="1">已提交</a-select-option>-->
                <a-select-option value="2">审批中</a-select-option>
                <a-select-option value="3">审批通过</a-select-option>
                <!--                <a-select-option value="5">审批驳回</a-select-option>-->
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="发布内容">
              <a-input placeholder="请输入发布内容模糊查询" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>


          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="downExportXls('pic_factory_report')">导出</a-button>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="updateApprovalBatch">
            <a-icon type="text"/>
            审批
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="imgPathS" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="record.imgPathS[0]" @click="clickImg(record.imgPathS)"/>
          </div>

        </template>
        <span slot="action" slot-scope="text, record">
        <a-popconfirm title="确定审批通过吗?" @confirm="() => updateApproval(record.id)"
        v-if="record.bpmStatus==2">
                  <a class="shenpion">审批</a>
        </a-popconfirm>
          <a v-if="record.bpmStatus!=2" class="shenpito">审批</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <!--<sfaPicFactory-modal ref="modalForm" @ok="modalFormOk"></sfaPicFactory-modal>-->
    <!--<img :src="bigImgSrc"/>-->
  </a-card>
</template>
<script>
  import '@/assets/less/TableExpand.less'
  import SfaPicUploadModal from './modules/SfaPicUploadModal'
  import {PageListMixin} from '@/mixins/PageListMixin'
  import {getAction,deleteAction} from '@/api/manage'
  import ARow from 'ant-design-vue/es/grid/Row'
  import ARangePicker from 'ant-design-vue/es/date-picker/RangePicker'

  export default {
    name: 'SfaPicUploadList',
    mixins: [PageListMixin],
    components: {
      ARangePicker,
      ARow,
      SfaPicUploadModal
    },
    data() {
      return {
        jianShow: '',
        leftjian: require('@/assets/leftjian.png'),
        jiantou: require('@/assets/jiantou.png'),
        message: '',
        imgIndex:0,
        showImg: false,
        imgSrc: [],
        description: '朋友圈打卡页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '打卡人姓名',
            align: "center",
            dataIndex: 'createName'
          },
          {
            title: '打卡日期',
            align: "center",
            dataIndex: 'createDate'
          },
          {
            title: '打卡时分秒',
            align: "center",
            dataIndex: 'createDateTime'
          },
          {
            title: '审批人姓名',
            align: "center",
            dataIndex: 'updateName'
          },
          {
            title: '审批时间',
            align: "center",
            dataIndex: 'updateDate'
          },
          // {
          //   title: '区域',
          //   align: "center",
          //   dataIndex: 'orgName'
          // },
          // {
          //   title: '备注',
          //   align: "center",
          //   dataIndex: 'remarks'
          // },
          {
            title: '状态',
            align: "center",
            dataIndex: 'bpmStatus_dictText'
          },
          {
            title: '发布类容',
            align: "center",
            dataIndex: 'title'
          },
          {
            title: '打卡拍照',
            align: "center",
            dataIndex: 'imgPathS',
            scopedSlots: {customRender: 'imgPathS'}
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'}
          }
        ],
        url: {
          list: window._CONFIG['domianSfaURL'] + "/picfactory/findFriendPageList",
          updateApproval: window._CONFIG['domianSfaURL'] + "/picfactory/updateApproval",
          updateApprovalBatch: window._CONFIG['domianSfaURL'] + "/picfactory/updateApprovalBatch",
          // startOrStopUrl: window._CONFIG['domianSfaURL']+ "/picfactory/status/startOrStop"
        },
        /* bigImgSrc: "",*/
      }
    },
    methods: {

      clickImg(path) {
        this.imgIndex = 0;
        //console.log(path);
        this.showImg = true;
        // 获取当前图片地址
        this.imgSrc = path;
        //console.log(this.imgSrc)
        this.jianShow = false;
        if (path.length>1){
          this.jianShow = true;
          // console.log(this.jianShow);
        }
      },
      viewImg() {
        this.showImg = false;
      },
      handleClickLeft(){
        if(this.imgIndex===0){
          this.imgIndex=(this.imgSrc.length)-1;
          return
        }
        if(this.imgIndex<this.imgSrc.length && this.imgIndex!==0){
          this.imgIndex--;
          return
        }
      },
      handleClickRight(){
        if(this.imgIndex<(this.imgSrc.length-1)){
          this.imgIndex++;
          return
        }
        if(this.imgIndex===(this.imgSrc.length-1)){
          this.imgIndex=0;
          return
        }

      },
      updateApproval: function (id) {
        if (!this.url.updateApproval) {
          this.$message.error("请设置url.updateApproval属性!")
          return
        }
        var that = this;
        getAction(that.url.updateApproval, {id: id}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      updateApprovalBatch: function () {
        if (!this.url.updateApprovalBatch) {
          this.$message.error("请设置url.updateApprovalBatch属性!")
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认通过",
            content: "是否通过选中数据?",
            onOk: function () {
              that.loading = true;
              deleteAction(that.url.updateApprovalBatch, {ids: ids}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },
      //   startorstop: function (status) {
      //     if (!this.url.startOrStopUrl) {
      //       this.$message.error("请设置url启用停用!")
      //       return;
      //     }
      //     if (this.selectedRowKeys.length != 1) {
      //       this.$message.warning('请选择一条记录！');
      //       return;
      //     } else {
      //       var id = this.selectedRowKeys[0];
      //       var that = this;
      //       that.loading = true;
      //       getAction(this.url.startOrStopUrl, {id: id, status: status}).then((res) => {
      //         if (res.success) {
      //           that.$message.success(res.message);
      //           that.loadData();
      //         } else {
      //           that.$message.warning(res.message);
      //         }
      //         that.loading = false;
      //       });
      //     }
      //   }
    }
  }
</script>

<style scoped>
  @import '~@assets/less/common.less';
  /*动画*/
  .fade-enter-active,
  .fade-leave-active {
    transition: all .2s linear;
    transform: translate3D(0, 0, 0);
  }

  .fade-enter,
  .fade-leave-active {
    transform: translate3D(100%, 0, 0);
  }

  /* bigimg */

  .img-view {
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  /*遮罩层样式*/
  .img-view .img-layer {
    position: fixed;
    z-index: 99998;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.7);
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  /*不限制图片大小，实现居中*/
  .img-view .img img {
    position: absolute;
    min-width: 50%;
    max-width: 50%;
    display: block;
    left: 0;
    right: 0;
    margin: auto;
    z-index: 99999;
  }
  .left {
    position: absolute;
    min-width: 20%;
    max-width: 20%;
    display: block;
    left: 0px;
    margin: auto;
    z-index: 99999;
    top: 50%;
  }
   .right {
    position: absolute;
    min-width: 20%;
    max-width: 20%;
    display: block;
    right: 0px;top: 50%;
    margin: auto;
    z-index: 99999;
  }
  .shenpito {
    color: #434e59;
  }
  .shenpion{
    color: #2eabff;
  }
</style>